package propertieslinguagem;

import java.awt.EventQueue;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Locale;
import java.util.ResourceBundle;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;

public class ChangeLocale {

    private JFrame frame;

    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    ChangeLocale window = new ChangeLocale();
                    window.frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    public ChangeLocale() {
        initialize();
    }

    private void initialize() {
        frame = new JFrame();
        frame.setBounds(100, 100, 450, 300);
        frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        FlowLayout flowLayout = new FlowLayout(FlowLayout.CENTER, 5, 5);
        frame.getContentPane().setLayout(flowLayout);

        JButton btnChangeLoc = new JButton("Change Locale");
        frame.getContentPane().add(btnChangeLoc);

        final JLabel lblLabel1 = new JLabel("New label");
        frame.getContentPane().add(lblLabel1);
        Locale.setDefault(new Locale("ja"));
        ResourceBundle r = ResourceBundle.getBundle("LocRes");
        lblLabel1.setText(r.getString("text1"));

        btnChangeLoc.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Locale.setDefault(new Locale("ja"));
                ResourceBundle r = ResourceBundle.getBundle("LocRes");
                // Manually iterate through all components :(
                lblLabel1.setText(r.getString("text1"));
                //
            }
        });
    }
}
